package com.a2v2.online.store.database.dao.contract;

import java.io.Serializable;
import java.util.List;

import com.a2v2.online.store.database.entity.BaseEntity;

/**
 *
 * @author aurionPro
 *
 * @param <T> Type of persistent class
 * @param <ID> Type of Id filed (generally will be Long)
 * Generic DAO which list basic and general db operations
 * used by any DAO.
 */
public interface GenericDAO<T extends BaseEntity, ID extends Serializable> {
    /**
    * @author aurionPro
    * This method is used to add new record
    * into database.
    * @param  pObj the class type object.
    * @return the class type object
    */
    T add(T pObj);
    /**
    * @author
    * This method is used to update record.
    * in database.
    * fields class type object.
    * @param  pObj the class type object.
    * @return
    */
    void update(T pObj);
    /**
    * @author
    * This method is used to delete record
    * from database.
    * fields object Id.
    * @param  pObj the class type object.
    * @return
    */
    void delete(T pObj);
    /**
    * @author
    * This method is used to add or update record.
    * in database.
    * fields class type object.
    * @param  pObj the class type object.
    * @return the entity object.
    */
    T saveOrUpdate(T pObj);
    /**
    * @author
     * This method is used to fetch requested record from database by Id.
     * @param pId the ID
     * @param pLock the lock on operation
     * @return class type object
     */
    T getById(ID pId, boolean pLock);
    /**
     * This method is used to fetch requested record from database by Id.
     * @param pId the ID
     * @return class type object
     */
    T getById(final ID pId);
    /**
     * @author
     * This method is used to fetch all record from database.
     * @return list of class type object
     */
    List<T> getAll();
    /**
     * @author
     * This method is used to fetch top record from database.
     * @param pCount the int
     * @return list of class type object
     */
    List<T> getTop(int pCount);
    /**
    * @author
    * This method is used to clear the memory cache
    * from current hibernate session .
    * fields class type object.
    */
    void clearMemoryCache();
    /**
    * @author
    * This method is used to attach object with current session
    * @param pObj class type object.
    */
	void attach(T pObj);
	/**
    * @author
    * This method is used to detach object
    * from current hibernate session.
    * @param pObj class type object.
    */
	void detach(T pObj);
	/**
    * @author
    * This methods is used to flush the
    * current hibernate session.
    */
    void flush();
    
    <FT> T getByFieldName(String fieldName, FT fieldValue);
    <FT> List<T> getAllByFieldName(String fieldName, FT fieldValue);   
    
}
